package com.wayne.testapp.activity;

import android.app.DownloadManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatButton;
import android.util.Log;
import android.view.View;

import com.wayne.testapp.R;
import com.wayne.testapp.service.DownloadService;
import com.wayne.testapp.utils.MD5;
import com.wayne.testapp.utils.MUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by wayne on 2016/06/29.
 */
public class TestDownloadActivity extends BaseActivity {
    DownloadManager downloadManager;
    @InjectView(R.id.bt_download)
    AppCompatButton btDownload;
    @InjectView(R.id.bt_pause)
    AppCompatButton btPause;
    @InjectView(R.id.bt_dialog)
    AppCompatButton btDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_test_download);
        ButterKnife.inject(this);
        downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

        try {
            String str = MUtils.encodeBase64File("/storage/emulated/0/smjr/20160620215158qua_smjrapp.jpg");

            Log.i("tags","--"+new MD5().toMD5(str)+"--");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @OnClick({R.id.bt_download, R.id.bt_pause, R.id.bt_dialog})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_download:
                Intent intent = new Intent(this, DownloadService.class);
//                String url = "http://shouji.360tpcdn.com/160617/a76159620f65878adf3da1775c933092/com.estrongs.android.pop_521.apk";
                String url2 = "http://tel.down.manhuaren.com/android/13/2016/6/28/manhuaren_2.0.0.8_dm5_1.apk";
//                String url3 = "http://cy.cr173.com/rootexplorer.apk";
                intent.putExtra("url", url2);
                startService(intent);
                break;
            case R.id.bt_pause:

                break;
            case R.id.bt_dialog:
                showDialog();
                break;
            default:
                break;
        }
    }


    private void showDialog() {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("正在下载xxx");
        View view = View.inflate(this, R.layout.dialog_download, null);
        ContentLoadingProgressBar pb = (ContentLoadingProgressBar) view.findViewById(R.id.pb);

        builder.setView(view);

        
    }


}
